﻿
/*******************************************************************************************
// ©2009 Microsoft Corporation.  This code is provided under the Microsoft Public License.
*******************************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ClientBilling
{
    public partial class Billing : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #region Repeater Data Binding

        protected void CallRecordRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            RepeaterItem repeaterItem = e.Item;

            BilledCallRecord record = e.Item.DataItem as BilledCallRecord;
            Repeater caseAllocationRepeater = e.Item.FindControl("CaseAllocationRepeater") as Repeater;

            if (record != null && caseAllocationRepeater != null)
            {
                IEnumerable<CaseAllocation> allocations = record.CaseAllocations.Where(allocation => allocation.PortionOfCall > 0);
                caseAllocationRepeater.DataSource = allocations;
                caseAllocationRepeater.DataBind();
            }
        }

        public static string FormatCallDetails(DateTime start, TimeSpan callLength)
        {
            return string.Format(" at {0:t} on {1:d} for {2} minutes", start, start, callLength.Minutes);
        }

        #endregion
    }
}
